#ifndef THREAD_POOL_H
#define THREAD_POOL_H

#ifdef __cplusplus
extern "C" {
#endif

#define TP_MAX_THREADS  8

struct threadpool;

typedef struct threadpool *threadpool_t;


/*
 * 创建线程池
 * @param num_thread    active threads in pool, number of thread is unchanged
 * @retrun  pointer to thread pool if success, or NULL
 */
threadpool_t thread_pool_create(int num_thread);

/*
 * 线程池任务函数
 * @param priv private data 
 * @return  1 if success, 0 for else
 */
typedef int(*thread_task_func)(void * /* priv*/);

/*
 * 向线程池添加任务
 * @param tp    pointer to thread pool
 * @param task  task routine to run
 * @param priv  private data for task routine
 * @return  int     1 if suceess, 0 for other
 */
int thread_pool_add_task(threadpool_t tp, thread_task_func func, void *priv);

/*
 * 销毁线程池
 * @param   tp      pointer to thread pool
 * @return  int     1 if success, 0 for other
 */
int thread_pool_destroy(threadpool_t tp);

#ifdef __cplusplus
}
#endif

#endif
